#include <iostream>
using namespace std;

void quick_sort(int* a,int len)
{
	if(len<=1){
		return;
	}
	int mid = len/2;
	int key = a[mid];
	int key_index = mid;

	int left = 0;
	int right = len-1;
	while(right>left)
	{
		while(a[left]<key)
		{
			left++;
		}
		if(a[left]>key)
		{
			a[key_index] = a[left];
			a[left] = key;
			key_index = left;
		}
		while(a[right]>key)
		{
			right--;
		}
		if(a[right]<key)
		{
			a[key_index] = a[right];
			a[right] = key;
			key_index = right;
		}
	}
	quick_sort(a,key_index);
	quick_sort(a+key_index+1,len-key_index-1);
		
}

int main()
{
	int a[10] = {6,1,4,2,5,8,9,7,0,3};
	quick_sort(a,10);
	for(int i = 0;i<10;i++)
	{
		cout<<*(a+i)<<" ";
	}
	return 0;
}
